package leetcode.N801_N900;


public class N844 {


    public static void main(String[] args) {
        System.out.println(backspaceCompare("a##c", "#a#c"));
    }


    static boolean backspaceCompare(String S, String T) {
        int sIndex = 0;
        int tIndex = 0;
        char[] s = new char[200];
        char[] t = new char[200];

        for (int i = 0; i < S.length(); i++) {
            char temp = S.charAt(i);
            if (temp == '#') {
                if (sIndex == 0) {
                    continue;
                }
                sIndex--;
            } else {
                s[sIndex++] = temp;
            }
        }

        for (int i = 0; i < T.length(); i++) {
            char temp = T.charAt(i);
            if (temp == '#') {
                if (tIndex == 0) {
                    continue;
                }
                tIndex--;
            } else {
                t[tIndex++] = temp;
            }
        }

        if (sIndex != tIndex) {
            return false;
        }

        for (int i = 0; i < sIndex; i++) {
            if (s[i] != t[i]) {
                return false;
            }
        }
        return true;
    }


}
